package com.zhang.Builder.example;

import java.util.ArrayList;

/**
 * @author ElloeStudy(Sifa Zhang)
 * @create 2022-03-04 15:18
 * To: 真常应物，真常得性，常清常静，常清静矣
 */
public abstract class CarModel {
    // 这个参数是各个基本方法执行的顺序
    private ArrayList<String> sequence = new ArrayList<>();
    // 四个基本参数(客户不需要关心这些方法怎么实现，所有方法为protected)
    protected abstract void start();
    protected abstract void stop();
    protected abstract void alarm();
    protected abstract void engineBoom();
    // 模板方法
    public final void run(){
        for (int i = 0; i < this.sequence.size(); i++) {
            String actionName = this.sequence.get(i);
            if (actionName.equalsIgnoreCase("start"))  // .equalsIgnoreCase忽略大小写 ,关键词为start
            {
                this.start();
            }else if (actionName.equalsIgnoreCase("stop")){
                this.stop();
            }else if (actionName.equalsIgnoreCase("alarm")){
                this.alarm();
            }else if (actionName.equalsIgnoreCase("engineboom")){
                this.engineBoom();
            }
        }
    }

    public final void setSequence(ArrayList<String> sequence){
        this.sequence = sequence;
    }
}
